#include "gofgame/dungeonkeeper/game/ui/HeroDieMessageBox.h"
#include "gofgame/dungeonkeeper/game/GameManager.h"
#include "gofgame/dungeonkeeper/mapscene/MapScene.h"
#include "gofgame/dungeonkeeper/loadingscene/LoadingScene.h"

using namespace gofgame::dungeonkeeper::game::ui;
using namespace gofgame::dungeonkeeper::game;
using namespace gofgame::dungeonkeeper::mapscene;
using namespace gofgame::dungeonkeeper::loadingscene;

USING_NS_CC;

bool HeroDieMessageBox::onInitDialog()
{
	CCSize winSize = CCDirector::sharedDirector()->getWinSize();

	CCLabelTTF *label = CCLabelTTF::create("Your hero is die,please try it.", "", 64);
	label->setPosition(ccp(winSize.width / 2, winSize.height / 2 + 50));
	this->addChild(label);

	CCMenuItemFont *liveMenuItem = CCMenuItemFont::create("GoLive", this, menu_selector(HeroDieMessageBox::liveMenuItemCallback));
	liveMenuItem->setPosition(ccp(winSize.width / 2 - 200, winSize.height / 2 - 50));

	CCMenuItemFont *restartMenuItem = CCMenuItemFont::create("Retry", this, menu_selector(HeroDieMessageBox::restartMenuItemCallback));
	restartMenuItem->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 50));

	CCMenuItemFont *backMenuItem = CCMenuItemFont::create("BackToMenu", this, menu_selector(HeroDieMessageBox::backMenuItemCallback));
	backMenuItem->setPosition(ccp(winSize.width / 2 + 200, winSize.height / 2 - 50));

	pushMenu(liveMenuItem);
	pushMenu(restartMenuItem);
	pushMenu(backMenuItem);

	setColor(ccc3(0,0,0));
	setOpacity(128);
	return true;
}

void HeroDieMessageBox::liveMenuItemCallback(CCObject *obj)
{
	GameManager::sharedGameManager()->getGameLayer()->heroReLive();
	this->removeFromParentAndCleanup(true);
}

void HeroDieMessageBox::restartMenuItemCallback(CCObject *obj)
{
	LoadingScene *loadingscene = LoadingScene::create();
	CCDirector::sharedDirector()->replaceScene(loadingscene);
	this->removeFromParentAndCleanup(true);
}

void HeroDieMessageBox::backMenuItemCallback(CCObject *obj) {
	MapScene *mp = MapScene::create();
	CCDirector::sharedDirector()->replaceScene(mp);
	this->removeFromParentAndCleanup(true);
}